package com.entrogy.dao;

import com.entrogy.bean.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface MessageMapper {

	@Select("SELECT pubcount_information.openid,gt.access_token,gt.template_id FROM weixin_information inner join pubcount_information on weixin_information.unionid=pubcount_information.unionid inner join gongzhonghao_token gt on pubcount_information.username=gt.username where  weixin_information.uid = #{id} limit 1")
	PubCountEntity getPubCountOpenidByid(@Param("id") String id);

	@Select("SELECT pubcount_information.openid,gongzhonghao_token.access_token,gongzhonghao_token.template_id  FROM weixin_information INNER JOIN pubcount_information on weixin_information.unionid=pubcount_information.unionid INNER JOIN gongzhonghao_token on pubcount_information.username = gongzhonghao_token.username  where weixin_information.phone=#{parentPhone} limit 1")
	PubCountEntity getPubCountOpenidByPhone(@Param("parentPhone") String parentPhone);

	/**
	 *  新增一个信息
	 * @param messageEntity
	 * @return
	 */
	int insertMessage(MessageEntity messageEntity);

	/**
	 *   获取类型
	 *
	 * @return
	 */
	List<Map<String,Object>> getChanggeType(Map<String,Object> map);

	@Select("select * from message_information where message_id=#{id}")
	MessageEntity getVisitorMessage(@Param("id") int id);

	@Select("select course_id from student_information where parent1_id=#{uid} or parent2_id=#{uid} union " +
			"select grade_id from student_information where parent1_id=#{uid} or parent2_id=#{uid}")
	List<String> getChildCourseid(String uid);

	List<MessageEntity> getMessageListToParent(@Param("courseIdList") List<String> courseIdList, @Param("start") int start, @Param("end") int end);

	@Select("${sql}")
	List<MessageEntity> getMessageListToUser(@Param("sql") String sql);

	/**
	 *   获取年级班级等
	 * @return
	 */
	List<ClassEntity>  getClassList(Map<String,Object> map);

	/**
	 *   获取年级班级等
	 * @return
	 */
	List<ClassEntity>  getClassList1(Map<String,Object> map);

	/**
	 *   获取任课老师的数据
	 * @param map
	 * @return
	 */
	List<CourseEntity>  getClassTeacherList(Map<String,Object>  map);


	/**
	 *   查询年级主任  班主任或者职员等的数据
	 * @param map
	 * @return
	 */
	List<UserEntity>  getpTypeList(Map<String,Object>  map);

	/**
	 *   查询某些任课老师  比如某个年级班级等
	 * @param map
	 * @return
	 */
	List<Map<String,Object>> getUsersbyBatchId(Map<String,Object>  map);

	/**
	 * 查询家长信息
	 * @param map
	 * @return
	 */
	List<ParentVisitorEntity>  getParentsbyBatchId(Map<String,Object>  map);

	/**
	 *  根据模板id查询模板内容
	 * @param template_id
	 * @return
	 */
	Template getTemplateContentById(@Param("template_id") int  template_id,@Param("school_code") int school_code);


	/**
	 * 根据类型和范围查询教师信息
	 * @param map
	 * @return
	 */
	List<UserEntity> listUserByType(Map<String, Object> map);

	/**
	 * 插入消息发送记录
	 * @param messageSendEntity
	 * @return
	 */
	int insertMessageRecord(MessageSendEntity messageSendEntity);

	/**
	 * 更新消息发送成功的记录
	 *
	 * @param messageRecordId
	 * @param success
	 * @return
	 */
	int updateMessageRecord(@Param("messageRecordId") Integer messageRecordId, @Param("success") Integer success);

	/**
	 * 查询通知发送的消息列表
	 * @param uid
	 * @return
	 */
	List<MessageEntity> listMessage(@Param("uid") String uid);
}
